package com.example.q_kang.hhh.home;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextPaint;

import com.bulong.rudeness.RudenessScreenHelper;
import com.example.q_kang.hhh.R;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.base.MVPActivity;
import com.sskj.base.adapter.slimadapter.IViewInjector;
import com.sskj.base.adapter.slimadapter.SlimAdapter;
import com.sskj.base.adapter.slimadapter.SlimInjector;
import com.sskj.base.base.App;
import com.sskj.base.bean.MessageListBean;
import com.sskj.base.bean.SendListBean;
import com.sskj.base.mvchelper.ModelRx2DataSource;
import com.sskj.base.utils.DateUtil;
import com.sskj.base.view.DividerLineItemDecoration;
import com.sskj.base.view.ToolBarLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;

/**
 * @author Hey
 * Create at  2019/04/11
 */
public class SendRecordActivity extends MVPActivity<SendRecordPresenter> {

    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter<SendListBean.SendBean> slimAdapter;
    private MVCCoolHelper<List<SendListBean.SendBean>> mvcHelper;
    private String type;
    private ModelRx2DataSource<SendListBean.SendBean> dataSource;

    @Override
    public int getLayoutId() {
        return R.layout.activity_send_record;
    }

    @Override
    public SendRecordPresenter getPresenter() {
        return new SendRecordPresenter();
    }

    @Override
    public void initView() {
        type = getIntent().getStringExtra("type");
        toolbar.setLeftButtonOnClickListener(view -> finish());
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setSecondToLastDraw(false)
                .setLastDraw(false)
                .setLeftPadding((int) RudenessScreenHelper.pt2px(this, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(this, 30))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(this, 1))
                .setDividerColor(ContextCompat.getColor(this, R.color.divider_s)));
        slimAdapter = SlimAdapter.create().register(R.layout.item_send, new SlimInjector<SendListBean.SendBean>() {
            @Override
            public void onInject(SendListBean.SendBean data, IViewInjector injector) {
                injector.text(R.id.tv_send_type, type + App.INSTANCE.getString(R.string.appJavaSendRecordActivity2))
                        .text(R.id.tv_money, data.getTo_money())
                        .text(R.id.tv_account, data.getTo_uid_account())
                        .text(R.id.tv_date, DateUtil.getDateFormat(Long.valueOf(data.getZf_time()) * 1000, DateUtil.PATTERN_J));
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        if (type.equals(App.INSTANCE.getString(R.string.appJavaSendRecordActivity3))) {
            dataSource = new ModelRx2DataSource<>(
                    (ModelRx2DataSource.OnLoadSource<SendListBean.SendBean>)
                            page -> mPresenter.getSendJiHuoList(page), 10);
        } else if (type.equals(App.INSTANCE.getString(R.string.appJavaSendRecordActivity4))) {
            dataSource = new ModelRx2DataSource<>(
                    (ModelRx2DataSource.OnLoadSource<SendListBean.SendBean>)
                            page -> mPresenter.getSendPaiDanList(page), 10);
        }
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();


//        Flowable.rangeLong(0, 8)
//                .map(i -> i + "")
//                .toList()
//                .subscribe(strings -> slimAdapter.updateData(strings));

    }

    @Override
    public void initData() {

    }

    public static void start(Context context, String type) {
        Intent intent = new Intent(context, SendRecordActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }
}
